/** 
    @file logger.hpp
    @brief Logger
*/

#ifndef PM3_LOGGER_HPP
#define PM3_LOGGER_HPP

#include <cstdio>
#include <string>

#include <OgreSingleton.h>

#include "signals/Signal.h"

namespace pm3 {

    /**
        @class LOGGER
        @brief Logger
    */
    class LOGGER: public Ogre::Singleton<LOGGER> {
    public:
            /**
                @brief Constructor
            */
            LOGGER();
            /**
                @brief Destructor
            */
            ~LOGGER();

            /**
                @brief Sets the file into which the log is written
                @param[in] r_file Reference to the filepath
            */
            inline void set_file( const std::string &r_file ) {
                m_file = r_file;
            }

            /**
                @brief Reports to the log
                @param[in] r_section Reference to the title of the section in which to post
                @param[in] fmt Log report format string
                @return True on success, otherwise false
            */
            bool report( const std::string &r_section, const char *fmt, ... );

            //! Report signal, called each time a message is reported to the log
            Gallant::Signal2< const std::string &, const std::string & > m_sig_report;

    private:
            //! Log file path
            std::string m_file;
            //! Sections
            std::vector<std::string> m_sections;
            //! Section contents
            std::vector<std::string> m_contents;

            /**
                @brief Gets a log section or adds one
                @param[in] r_title Reference to section title
                @return Section index
                @note There should be only a few sections in total, which is why this function has not been optimized for speed
            */
            int get_section( const std::string &r_title );
    };

    //! Logger global
    extern LOGGER g_logger;
}

#endif

